/*
 * Created by JFormDesigner on Mon Jul 01 17:32:09 CST 2024
 */

package scct.hys.ui;

import scct.hys.dao.MovieDao;
import scct.hys.model.Movie;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author 26984
 */
public class DlgMovieDel extends JDialog {
    int id;

    public DlgMovieDel(Window owner,int id) {
        super(owner);
        initComponents();
        this.id=id;
        initView();

    }

    private void initView() {
        MovieDao movieDao=new MovieDao();
        Movie movie=movieDao.getMovieById(id);
    }

    private void btnDel(ActionEvent e) {
        // TODO add your code here
        MovieDao movieDao=new MovieDao();
        if (movieDao.delMovie(id)){
            JOptionPane.showMessageDialog(this,"删除成功");
            dispose();
        }

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - 韩月生
        txtName = new JLabel();
        btnDel = new JButton();
        btnCancel = new JButton();

        //======== this ========
        setTitle("\u5220\u9664\u5f71\u7247");
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- txtName ----
        txtName.setText("\u786e\u5b9a\u5220\u9664\u8fd9\u4e2a\u5f71\u7247\u5417\uff1f");
        txtName.setFont(txtName.getFont().deriveFont(txtName.getFont().getSize() + 6f));
        contentPane.add(txtName);
        txtName.setBounds(new Rectangle(new Point(90, 45), txtName.getPreferredSize()));

        //---- btnDel ----
        btnDel.setText("\u786e\u5b9a\u5220\u9664");
        btnDel.addActionListener(e -> btnDel(e));
        contentPane.add(btnDel);
        btnDel.setBounds(new Rectangle(new Point(45, 110), btnDel.getPreferredSize()));

        //---- btnCancel ----
        btnCancel.setText("\u53d6\u6d88");
        contentPane.add(btnCancel);
        btnCancel.setBounds(new Rectangle(new Point(210, 110), btnCancel.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(355, 195);
        setLocationRelativeTo(null);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - 韩月生
    private JLabel txtName;
    private JButton btnDel;
    private JButton btnCancel;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
